package com.bw.lib_base.net

import android.content.Context
import androidx.room.Room
import com.bw.lib_base.db.ParkDatabase
import com.bw.lib_base.db.RepairDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * 提供依赖注入模块，用于生成ApiService的实例
 */
@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {
    /**
     * 提供ApiService实例的函数
     *
     * @return ApiService实例，通过RetrofitUtil创建
     */
    @Provides
    @Singleton
    fun getApiService(): ApiService = RetrofitUtil.retrofit.create(ApiService::class.java)
    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDatabase{
        return Room.databaseBuilder(context, ParkDatabase::class.java,"park2301.db")
            .allowMainThreadQueries()
            .build()
    }

    @Provides
    @Singleton
    fun getRepairDao(database: ParkDatabase):RepairDao = database.getRepairDao()
}
